import 'dart:async';

import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/http/apis/user.dart';
import 'package:qgchat/http/models/attentionModel.dart';
import 'package:qgchat/http/models/fansModel.dart';

class AttentionOrFansBloc implements BlocBase {

  @override
  void dispose() {
    _fansController.close();
    _attentionController.close();
  }

// STREAMS======================================================================

  /// 粉丝stream
  StreamController<List<FansModel>> _fansController = StreamController.broadcast();
  Sink<List<FansModel>> get _fansSink => _fansController.sink;
  Stream<List<FansModel>> get outFansStream => _fansController.stream;

  /// 关注stream
  StreamController<List<AttentionModel>> _attentionController = StreamController.broadcast();
  Sink<List<AttentionModel>> get _attentionSink => _attentionController.sink;
  Stream<List<AttentionModel>> get outAttentionStream => _attentionController.stream;


// HANDLING=====================================================================

  /// 获取粉丝列表
  void getFansList() async {
    List<FansModel> result = await UserApis.getFansList();
    if (!_fansController.isClosed) {
      _fansSink.add(result);
    }
  }

  /// 获取关注列表
  void getAttentionList() async {
    List<AttentionModel> result = await UserApis.getAttentionList();
    if (!_attentionController.isClosed) {
      _attentionSink.add(result);
    }
  }

}